﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;
using System.Data;
using ReportMobile.inc;

namespace ReportMobile.v2 {
    public partial class RepaymentRate : System.Web.UI.Page {
        public DataSet ds = new DataSet();
        public DataTable dt = new DataTable();
        public Common cm = new Common();
        public string repayYear;    //用户选择的年度
        public string daedTime;     //截止时间
        public double rmbTotal;     //借出合计
        public string areaName;     //区域名称
        protected void Page_Load(object sender, EventArgs e) {
            if (Request.QueryString["area"] == null)
                return;
            string urlArea = Request.QueryString["area"].ToString();
            areaName = urlArea == "cyq" ? "川渝区" : "非川渝区";
            string[] xVal = new string[10];
            double[] yVal = new double[10];
            //暂时没启用可选择年度查看还款率的功能
            repayYear = string.Format("{0:yyyy}", DateTime.Now);
            daedTime = Convert.ToInt32(repayYear) < Convert.ToInt32(string.Format("{0:yyyy}",DateTime.Now)) ? 
                        repayYear + "-12-31 00:00:00" : DateTime.Now.ToString();
            dt = cm.ExecuteProcedure("Feed_RepaymentRate @sfYear = " + repayYear + ",@sfArea = " + urlArea);
            
            rmbTotal = Convert.ToDouble(dt.Compute("sum(借出总额)",""));
            for (int i = 0; i < dt.Rows.Count; i++) {
                yVal[i] = Math.Round(Convert.ToDouble(dt.Rows[i]["借出总额"]) / rmbTotal * 100, 1);
                //xVal[i] = dt.Rows[i]["公司简称"].ToString() + "：" + string.Format("{0:0%}",yVal[i]);
                xVal[i] = dt.Rows[i]["公司简称"].ToString();
            }
            //序列名称Series1区分大小写，并且y值不能绑定字符串——#
            chartRate.Series[0].Points.DataBindXY(xVal, yVal);
            chartRate.Series[0].Label = "#VALY" + "%";  //设置y柱的数据标签显示内容
            chartRate.Series[0].LegendText = "#VALX";   //设置图例的显示内容
            chartRate.Legends[0].Docking = Docking.Bottom;
            chartRate.Series[0]["PieLabelStyle"] = "Outside";   //设置y轴数据标签显示位置
            chartRate.Series[0]["PieLineColor"] = "Black";      //设置y轴数据标签的指示线
            dt.DefaultView.Sort = "还款率 desc";
            ds.Tables.Add(dt.DefaultView.ToTable());
            rptRate.DataSource = ds;
            rptRate.DataBind();
        }
    }
}